#!/usr/bin/env python3
# -*- coding: utf-8 -*-

from PIL import Image, ImageDraw, ImageFont
import os

def create_placeholder_images():
    image_dir = "/Users/wangqi/Documents/code/privateorder/pan/halo/application/src/main/resources/themes/alibaba-b2b-theme/assets/images"
    
    print("🎨 创建占位图片...")
    
    # 定义要创建的图片
    images_to_create = [
        ("hero-slide-1.jpg", 1920, 600, "产品展示 1", "#FF6A00"),
        ("hero-slide-2.jpg", 1920, 600, "产品展示 2", "#FF6A00"),
        ("hero-slide-3.jpg", 1920, 600, "产品展示 3", "#FF6A00"),
        ("logo.png", 200, 80, "LOGO", "#FF6A00"),
        ("company-overview.jpg", 800, 600, "公司概况", "#FF6A00"),
        ("product-1.jpg", 400, 300, "产品 1", "#FF6A00"),
        ("product-2.jpg", 400, 300, "产品 2", "#FF6A00"),
        ("product-3.jpg", 400, 300, "产品 3", "#FF6A00"),
        ("product-4.jpg", 400, 300, "产品 4", "#FF6A00"),
        ("product-5.jpg", 400, 300, "产品 5", "#FF6A00"),
        ("product-6.jpg", 400, 300, "产品 6", "#FF6A00"),
        ("product-7.jpg", 400, 300, "产品 7", "#FF6A00"),
        ("product-8.jpg", 400, 300, "产品 8", "#FF6A00"),
        ("news-1.jpg", 400, 300, "新闻 1", "#FF6A00"),
        ("news-2.jpg", 400, 300, "新闻 2", "#FF6A00"),
        ("news-3.jpg", 400, 300, "新闻 3", "#FF6A00"),
        ("wechat-qr.jpg", 200, 200, "微信二维码", "#FF6A00"),
        ("product-placeholder.jpg", 400, 300, "产品占位图", "#FF6A00"),
        ("news-placeholder.jpg", 400, 300, "新闻占位图", "#FF6A00"),
        ("product-detail-2.jpg", 800, 600, "产品详情 2", "#FF6A00"),
        ("product-detail-3.jpg", 800, 600, "产品详情 3", "#FF6A00"),
    ]
    
    for filename, width, height, text, color in images_to_create:
        file_path = os.path.join(image_dir, filename)
        
        try:
            # 创建新图片
            img = Image.new('RGB', (width, height), color)
            draw = ImageDraw.Draw(img)
            
            # 尝试使用中文字体，如果没有则使用默认字体
            try:
                font = ImageFont.truetype("/System/Library/Fonts/PingFang.ttc", 40)
            except:
                font = ImageFont.load_default()
            
            # 计算文本位置
            text_bbox = draw.textbbox((0, 0), text, font=font)
            text_width = text_bbox[2] - text_bbox[0]
            text_height = text_bbox[3] - text_bbox[1]
            
            # 绘制文本
            position = ((width - text_width) // 2, (height - text_height) // 2)
            draw.text(position, text, fill="white", font=font)
            
            # 保存图片
            img.save(file_path, quality=85)
            
            print(f"  ✅ 创建成功: {filename} ({width}x{height})")
            
        except Exception as e:
            print(f"  ❌ 创建失败: {filename} - {str(e)}")
    
    # 创建简单的favicon
    try:
        favicon_path = os.path.join(image_dir, "favicon.ico")
        favicon_img = Image.new('RGB', (32, 32), "#FF6A00")
        favicon_img.save(favicon_path)
        print(f"  ✅ 创建成功: favicon.ico (32x32)")
    except Exception as e:
        print(f"  ❌ 创建失败: favicon.ico - {str(e)}")
    
    print("\n🎉 所有图片创建完成！")
    
    # 显示创建的文件信息
    print("\n📋 创建的文件信息:")
    for filename in sorted(os.listdir(image_dir)):
        if filename.endswith(('.jpg', '.png', '.gif', '.ico')):
            file_path = os.path.join(image_dir, filename)
            if os.path.isfile(file_path):
                file_size = os.path.getsize(file_path)
                print(f"  {filename}: {file_size} bytes")

if __name__ == "__main__":
    create_placeholder_images()